package com.hemerasolutions.v2trainer.component;


import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;

import com.hemerasolutions.v2trainer.component.interfaces.BaseComponentInterface;
import com.hemerasolutions.v2trainer.controller.BaseBean;

public class BaseComponent extends BaseBean implements BaseComponentInterface {

	private static final long serialVersionUID = 1L;
	
	
	@Override
	public String getJqueryComponentId(){

		String label = new String();	
		
		FacesContext facesContext = FacesContext.getCurrentInstance();
		ELContext elContext = facesContext.getELContext();
		ValueExpression valueExpression = facesContext.getApplication().getExpressionFactory().createValueExpression(elContext, "#{cc.clientId}", String.class);

		label = new String((String) valueExpression.getValue(elContext));			
		
		label = label.replace(":", "\\\\:");
		
		label = "#" + label;
		
		return label;
		
	}


	
	@Override
	public String formatJqueryComponentId(String id){
		String label = new String();	
		
		label = id;			
		
		label = label.replace(":", "\\\\:");
		
		label = "#" + label;
		
		return label;
	
	}



	@Override
	public void refresh() {
		//Not implemented in super
	}
	
	

}
